﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Web.UI;

namespace AiXiu.WebSite
{
    /// <summary>
    /// 登录页
    /// </summary>
    public partial class Login : Page
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string userName = txtUserName.Text;
                string password = txtPassword.Text;
                IUserBLL userBLL = new UserBLL();
                OperResult<TBUsers> result= userBLL.LoginByUserName(userName, password);
                if (result.StatusCode == StatusCode.Succeed)
                {
                    //获取当前登录的用户信息
                    TBUsers user = result.Result;
                    //缓存用户的信息
                    IdentityManager.SaveUser(user);

                    //读取用户信息
                    //TBUsers userinfo= IdentityManager.ReadUser();

                    //跳转页面
                    this.Redirect("logingsuccess", "Default.aspx");
                }
                else
                {
                    this.Alert("loginfail", result.Message);
                }
            }
        }
    }
}